package com.itheima.exam.controller;

import com.itheima.exam.pojo.Result;
import com.itheima.exam.pojo.Warehouse;
import com.itheima.exam.pojo.WarehouseRestock;
import com.itheima.exam.service.WarehouseService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 仓库管理
 */
@RestController
@RequestMapping("/warehouse")
@Slf4j
public class WarehouseController {
    @Resource
    private WarehouseService warehouseService;

    /**
     * 仓库列表查询
     *
     * @param list 数据
     * @return 仓库列表
     */
    @PostMapping("/list")
    public Result listWarehouses(@RequestBody Map<String, Object> list) {
        List<Warehouse> warehouses = warehouseService.listWarehouses(list);
        if (warehouses == null) return Result.error("查询失败");
        return Result.success(warehouses);
    }

    /**
     * 出库
     *
     * @param restock 出库数量
     * @return 出库结果
     */
    @GetMapping("/out/{restock}")
    public Result outWarehouse(@PathVariable Integer restock) {
        log.info("出库请求==> 出库数量: {}", restock);
        List<WarehouseRestock> restockResult = warehouseService.outWarehouse(restock);
        if (restockResult == null) return Result.error("出库失败");
        return Result.success(restockResult);
    }


}
